package com.vs.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.vs.util.Constants;

public class CustomContextListener implements ServletContextListener {

	private Logger log = null;

	@Override
	public void contextInitialized(ServletContextEvent contextEvent) {
		System.out.println("context initialized");
		String log4jLocation = contextEvent.getServletContext()
				.getInitParameter("log4jLocation");
		System.out.println("log4jLocation=" + log4jLocation);
		String contextPath = contextEvent.getServletContext().getContextPath();
		System.out.println("contextPath=" + contextPath);
		String realPath = contextEvent.getServletContext().getRealPath(
				log4jLocation);
		System.out.println("realPath=" + realPath);
		PropertyConfigurator.configure(realPath);
		log = Logger.getLogger("prod1");
		log.debug("context initialized");
		Constants.log = log;
	}

	@Override
	public void contextDestroyed(ServletContextEvent contextEvent) {
		System.out.println("context destroyed");
		log.debug("context destroyed");
	}

}
